$(function(){
	//初始化表格
	$('#YuanYindg').datagrid({
	    url:'YuanYinF',
	    /* queryParams:{
	    	deptno:10
	    }, */
	    columns:[[
			{field:'RSNID',checkbox:true,order:'desc',title:'原因编号',width:100,align:'center'},
			{field:'RSNREASON',title:'原因',width:1,align:'center'},
			{field:'RSNREM',title:'备注',width:1,align:'center'},
			{field:'caozuo',fixed:false,width:1,formatter:operate_formatter,title:'操作',align:'center'}
		]],
	    toolbar:'#YuanYintb',
	    pagination:true,
	    pageNumber:1,
	    pageSize:5,
	    pageList:[5,10,15]
	});
	
	function operate_formatter(value, row, index) {
		return "<button class='easyui-linkbutton' onclick='deleteYY("+row.RSNID+")'>删除</button> ";
	}
	
	//点击提交
	$("#subYY").click(function(){
		var rsnid = $("#RSNID").val();
		var rsnreason = $("#RSNREASON").val();
		if(rsnreason==null || rsnreason=="null" || rsnreason==""){
			return alert("原因不能为空！");
		}
		var rsnrem = $("#RSNREM").val();
		
		$.ajax({
			url:"updateYY",
			type:"post",
			data:{"rsnid":rsnid,"rsnreason":rsnreason,"rsnrem":rsnrem},
			success:function(data){
				$('#YuanYindg').datagrid('reload');
			}
		});
		
		//清空表单
		$("#RSNID").val("");
		$("#RSNREASON").val("");
		$("#RSNREM").val("");   
		
		
		$("#YuanYinwin").window("close");
	});
	
	//双击行事件
//	$("#YuanYindg").datagrid({
//		//rowData是当前选中行的数据，是json字符串格式
//		onDblClickRow:function(rowIndex,rowData){
//			$("#YuanYinwin").window("open");
//			$("#RSNID").val(rowData["RSNID"]);
//			$("#RSNREASON").val(rowData["RSNREASON"]);
//			$("#RSNREM").val(rowData["RSNREM"]);
//		}
//	});
	
	//显示
	$("#YuanYinadd").click(function(){
		$("#RSNID").val("");
		$("#RSNREASON").val("");
		$("#RSNREM").val("");   
		$("#YuanYinwin").window("open");
	});
});

//删除方法
function deleteYY(RSNID){
	deleteBG("deleteYY","YuanYindg",{"RSNID":RSNID});
}